<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="css/demo.css"/>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/animate-custom.css"/>
    <title>会员资料修改</title>
    <style>
        .pic {
            border: 3px solid skyblue;
            width: 100px;
            height: 100px;
            border-radius: 80px;
            position: relative;
            left: 10%;
        }
        li {
            float: left;
            width: 8%;
            position: relative;
            left: 38%;
            font-size: 20px;
            padding-top: 1%;
        }
    </style>
</head>
<body>
<div class="container">
    <header>
        <h1><span>会员资料修改</span></h1>
        <nav class="codrops-demos">
            <?php
            if (isset($_SESSION['loggedUsername']) && $_SESSION['loggedUsername']) {
                ?>
                <h2>欢迎<strong><?php echo $_SESSION['loggedUsername'] ?></strong>登录会员管理系统
                </h2>
                <?php
            }
            ?>
        </nav>
        <nav>
            <ul>
                <li><a href="index.php"><strong>首页</strong></a></li>
                <li><a href="admin.php"> <strong>会员登录日志</strong></a></li>
                <li><a href="zhuxiao.php"> <strong>注销</strong></a></li>
            </ul>
        </nav>
    </header>
    <?php
    if (!isset($_SESSION['loggedUsername']) or !$_SESSION['loggedUsername']) {  //说明未登录
        echo "<script>alert('本页面需要登录后才能访问，请登录！');location.href='index.php';</script>";
        exit;
    }
    include_once "conn.php";
    $sql = "select * from userinfo where username = '" . $_SESSION['loggedUsername'] . "'";
    $result = mysqli_query($conn, $sql);
    $num = mysqli_num_rows($result);
    if (!$num) { //当前用户不存在
        echo "<script>alert('当前用户不存在！');location.href='index.php';</script>";
        exit;
    } else { //说明找到了当前用户
        $info = mysqli_fetch_array($result, 1);
    }
    ?>
    <section>
        <div id="container_demo">
            <div id="wrapper">
                <div id="login" class="animate form">
                    <form action="modifyxiugai.php" method="post" enctype="multipart/form-data">
                        <p>
                            <label data-icon="u">用户名</label>
                            <input id="ul" name="ul" value="<?php echo $info['username']; ?>" readonly/>
                        </p>
                        <p>
                            <label data-icon="p">密码</label>
                            <label id="pwTips"></label>
                            <input id="pw" name="pw" placeholder="不修改密码请留空"/>
                        </p>
                        <p>
                            <label data-icon="p">确认密码</label>
                            <label id="cpasswordTips"></label>
                            <input id="cpassword" name="cpassword" type="password"
                                   placeholder="确认你输入的密码"/>
                        </p>
                        <p>
                            <label data-icon="e">邮箱</label>
                            <input id="email" name="email" value="<?php echo $info['email'] ?>"/>
                        </p>
                        <p>
                            <label data-icon="u">年龄</label>
                            <input id="age" name="age" value="<?php echo $info['age'] ?>"/>
                        </p>
                        <p>
                            <label>性别：</label>
                            <input type="radio" name="sex" value="男"
                                   <?php if ($info['sex'] == "男"){ ?>checked<?php } ?>>男
                            <input type="radio" name="sex" value="女" <?php if ($info['sex'] == "女"){ ?>checked<?php } ?>
                                   style="margin-left:30px ">女
                        </p>
                        <p>
                            <label>爱好：</label>
                            <input type="checkbox" name="fav[]" value="听音乐"
                                   <?php if (!(strpos($info['fav'], '听音乐') === false)){ ?>checked<?php } ?>>听音乐
                            <input type="checkbox" name="fav[]" value="玩游戏"
                                   <?php if (!(strpos($info['fav'], '玩游戏') === false)){ ?>checked<?php } ?>>玩游戏
                            <input type="checkbox" name="fav[]" value="踢足球"
                                   <?php if (!(strpos($info['fav'], '踢足球') === false)){ ?>checked<?php } ?>>踢足球
                        </p>
                        <p>
                            <label>头像</label>
                        </p>
                        <p>

                            <!--判断当前登录用户是否有头像-->
                            <?php
                            include_once "conn.php";
                            $sql = "select * from userinfo where username = '" . $_SESSION['loggedUsername'] . "'";
                            $result = mysqli_query($conn, $sql);
                            $info = mysqli_fetch_array($result);
                            if ($info['pic']) {
                                ?>
                                <img class="pic" id="pic" src="upload/<?php echo $info['pic'] ?>"
                                     style="cursor: pointer" title="点击查看头像">
                                <?php
                            }
                            ?>
                        </p>
                        <p>
                            <label>更换头像(默认不更换)</label>
                            <input id="pic" name="pic" type="file">
                        </p>
                        <p>
                            <label data-icon="u">个人简介</label>
                            <input id="ren" name="ren" value="<?php echo $info['ren'] ?>"/>
                        </p>
                        <p class="login button" id="b">
                            <input type="submit" value="修改"/>
                        </p>
                        <p class="change_link">
                            不想修改？
                            <a href="index.php#tologin" class="to_register"> 去首页 </a>
                        </p>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
</body>
<script src="js/jquery-1.9.1.min.js"></script>
<script>
    $(function () {
        $("#cpassword").blur(function () {
            if ($("#pw").val() !== $("#cpassword").val()) {
                $("#cpasswordTips").html("<span style='color:red'>两次密码不一致请修改</span>");
            }
            else {
                if ($("#cpassword").val() !== "") {
                    $("#cpasswordTips").html("<span style='color:darkgreen'>密码相同 </span>");
                }
                else if ($("#pw").val() == "" && $("#cpassword").val() == "") {
                    $("#cpasswordTips").html("<span style='color:red'></span>");
                }
                else {
                    ("#cpasswordTips").html("<span style='color:red'></span>");
                }
            }
        })
    });
    $(function () {
        $("#pic").click(function () {
            $("#pic").css("transform", "scale(2)");
            $("#pic").click(function () {
                $("#pic").css("transform", "scale(1)");
            })
        });
    });
</script>
</html>
